package com.liangtian.mdm.system.business.service.impl;

import com.liangtian.mdm.system.business.dao.SysBusinessDao;
import com.liangtian.mdm.system.business.model.SysBusiness;
import com.liangtian.mdm.system.business.service.SysBusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysBusinessServiceImp implements SysBusinessService {

    //注入dao
    @Autowired
    SysBusinessDao SysBusinessDao;

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月12日上午10:08:19
     */

    @Override
    public List<SysBusiness> sysBusTree(SysBusiness sysBusiness) {
        return SysBusinessDao.querySysBusTree(sysBusiness);

    }

    @Override
    public List<SysBusiness> sysBusTreeForWk(SysBusiness sysBusiness) {
        return SysBusinessDao.querySysBusTreeForWk(sysBusiness);

    }

    @Override
    public List<SysBusiness> sysBusTreeForButton(SysBusiness sysBusiness) {
        return SysBusinessDao.querySysBusTreeForButton(sysBusiness);

    }

    @Override
    public List<SysBusiness> sysBusTreeForView(SysBusiness sysBusiness) {
        return SysBusinessDao.querySysBusTreeForView(sysBusiness);

    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月12日上午10:08:19
     */

    @Override
    public PageInfo queryBusByContion(SysBusiness sysBusiness) {
        PageInfo<List<SysBusiness>> pageInfo = null;
        try {
            Object pNo = sysBusiness.getPageNum();
            int pageNum, pageSize;
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(sysBusiness.getLimit());// 模型定义页面要显示数据条数
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）

            List<SysBusiness> sysBusList = SysBusinessDao.queryBusByContion(sysBusiness);
            pageInfo = new PageInfo(sysBusList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;


    }


    @Override
    public PageInfo queryBusByContion2(SysBusiness sysBusiness) {
        PageInfo<List<SysBusiness>> pageInfo = null;
        try {
            Object pNo = sysBusiness.getPageNum();
            int pageNum, pageSize;
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(sysBusiness.getLimit());// 模型定义页面要显示数据条数
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）

            List<SysBusiness> sysBusList = SysBusinessDao.queryBusByContion2(sysBusiness);
            pageInfo = new PageInfo(sysBusList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;


    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @author : xiaoliu
     * @date :2016年10月13日上午9:23:44
     */

    @Override
    public void insertBusiness(SysBusiness sysBusiness) {

        SysBusinessDao.insertBusiness(sysBusiness); //前台插入菜单

    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月13日下午4:03:03
     */

    @Override
    public SysBusiness queryBusById(SysBusiness sysBusiness) {

        return SysBusinessDao.queryBusById(sysBusiness);


    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param map
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月14日上午10:54:37
     */

    @Override
    public int deleteBus(Map<String, Object> map) {
        int m = 0;
        List<String> idlist = (List<String>) map.get("idsList");
        if (0 != idlist.size()) {
            m = SysBusinessDao.deleteBus(map);
            return m;
        }
        return m;
    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月17日下午12:59:34
     */

    @Override
    public int checkBusName(String busName) {
        Map<String, Object> map = new HashMap<>();
        map.put("busName", busName);//业务类型名称
        return SysBusinessDao.checkBusName(map);

    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月17日下午12:59:34
     */
    @Override
    public int checkBusTableName(String busTable, String dataType) {
        Map<String, Object> map = new HashMap<>();
        map.put("busTable", busTable);
        map.put("dataType", dataType);
        return SysBusinessDao.checkBusTableName(map);

    }


    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月17日下午12:59:34
     */

    @Override
    public int checkBusNode(String busId) {
        return SysBusinessDao.checkBusNode(busId);

    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @param : @return
     * @author : xiaoliu
     * @date :2016年10月17日下午4:29:41
     */

    @Override
    public int checkBusNameTwo(SysBusiness sysBusiness) {

        int i = 0;
        i = SysBusinessDao.selectAllBusName(sysBusiness);
        return i;
    }

    @Override
    public int checkBusTableNameTwo(SysBusiness sysBusiness) {

        int i = 0;
        i = SysBusinessDao.selectAllBusTableName(sysBusiness);
        return i;
    }

    /*** <p>Title:</p>
     * <p>Description: TODO</p>
     * @param : @param sysBusiness
     * @author : xiaoliu
     * @date :2016年10月17日下午4:58:34
     */

    @Override
    public void updateBus(SysBusiness sysBusiness) {

        SysBusinessDao.updateBus(sysBusiness);
    }

    @Override
    public List<Map<String, Object>> queryDataTables(List<String> Lst) {
        return SysBusinessDao.queryDataTables(Lst);
    }

    @Override
    public List<SysBusiness> queryCodeSysBusTree(Map<String, Object> param) {
        return SysBusinessDao.queryCodeSysBusTree(param);
    }


}
